<?php

require_once 'Interfaces/AIS_DocCommentTag.php';
/**
 * This is a implementation of the AIS_DocCommentTag interface.
 */
class AIS_DocCommentTagImpl implements AIS_DocCommentTag
{
	/**
	 * This creates a new DocCommentTag. The passed parameter nrOfValues specifies
	 * how many values this DocCommentTag will have. For example, if we have a tag like:
	 * "@param double $name this is a parameter" and we define that the tag has 2 values, we would
	 * get following 2 values:
	 * 1: double
	 * 2: $name this is a parameter
	 * 
	 * Specifiying 3 values gives following:
	 *  1: double
	 *  2: $name
	 *  3: this is a parameter
	 *  
	 * @param string $line The line containing the Tag
	 * @param int $nrOfValues how many values does the tag have
	 */
	public function __construct($line, $nrOfValues)
	{
		$this->name = trim(strtok($line," \t"));
		$this->extractValues($nrOfValues);
	}
	
	private function extractValues($nrOfValues)
	{
		for ($i =0; $i < $nrOfValues; $i++)
		{
			
			if ($i == $nrOfValues - 1)
			{
				$tok = strtok("");
				if (!$tok)
				{
					return;
				}
				array_push($this->values, trim($tok));
			}
			else{
				$tok = strtok(" \t");
				if (!$tok)
				{
					return;
				}
				array_push($this->values, trim($tok));
			}
			
		}
	}
	/**
	 * @var string
	 */
	private $name;
	/**
	 * @var array
	 */
	private $values = array();
	/**
	 * Returns the name of this tag. For example, @param has name "param".
	 * @return The name of this tag
	 */
	public function getName()
	{
		return $this->name;
	}
	/**
	 * This method returns the ith value of the tag. For example, the tag
	 * "@param double $a this is a comment" would have 3 values: 
	 * double			:  The param value
	 * $a				:  The param name
	 * this is a comment:  The comment
	 * 
	 * @return the ith value of this Tag
	 * @param int $i
	 */
	public function getValue($i)
	{
		return $this->values[$i];
	}
	
}

?>